function isMatch(left: string,right: string){
    let flag: boolean = false;
    if(left === '(' && right === ')') flag = true;
    if(left === '[' && right === ']') flag = true;
    if(left === '{' && right === '}') flag = true;
    return flag;
}

function isValid(s: string): boolean {
    
    if(s.length%2!== 0){
        return false;
    }
    const left: string = '([{';
    const right: string = ')]}';

    if(s.length === 1 && right.includes(s[0])){
        return true;
    }

    const stack1: any = [];//左括号入栈，右括号栈顶匹配

    for(let i = 0 ; i < s.length; i++){
        if(left.includes(s[i])){
            stack1.push(s[i]);
        }
        if(right.includes(s[i])){// 右括号则与栈顶匹配
            if(isMatch(stack1[stack1.length-1],s[i])){
                stack1.pop();//匹配则出栈
            }else{
                return false;// 不匹配时直接返回false
            }
            
        }
        
    }
    return stack1.length === 0;
};

let s = "([}}])";
console.log(isValid(s));